/*
 * AtInstructionDescription.java
 * 
 * last update: 15.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 *
 * Obs:  
 */

package engine;

import java.util.*;

/**
 * Implements the @(...) instruction description
 */
class AtInstructionDescription extends InstructionDescription{

	InstructionDescription blockDescription;
	Vector monitorDescriptions;

	AtInstructionDescription(int delayBefore, int line,
			NameSpaceDescription nsd,
			Vector monitorDescriptions, 
			InstructionDescription blockDescription){
		super(delayBefore, line, nsd);
		this.blockDescription = blockDescription;
		this.monitorDescriptions = monitorDescriptions;
	}

	DefaultInstruction instantiate(NameSpace ns)throws ParseException{

		AtInstruction ati = new AtInstruction(ns, delayBefore, this,
				blockDescription == null ? null :
					blockDescription.instantiate(ns));
		try {
			for (Enumeration e = monitorDescriptions.elements() ;
			e.hasMoreElements();)
				ati.addMonitor((ValueChangeMonitor)
						( (ValueChangeMonitorDescription)e.nextElement() ).
						instantiate(ns) );
			return ati;
		} catch(ParseException ex) {
			xConsole.dumpStack(ex);
			throw new ParseException(super.toString() + " error:" + ex);
		}
	}

	public String toString() {
		String result = super.toString() + "@(";
		Enumeration e = monitorDescriptions.elements();
		while (true) {
			result += e.nextElement();
			if(e.hasMoreElements()) result += " OR ";
			else break;
		}
		return result+" )";
	}
}



